<?php

class SupervisoresController extends AppController {

    public $name = 'Supervisores';
    public $uses = array('Supervisor');

    //metodos
    function index() {
        $supervisores = $this->paginate('Supervisor');
        $this->set(compact('supervisores'));
    }

    function ver($id = null) {//sin nulo no funca?? //ver
        $this->Supervisor->id = $id; //esto cambia la referencia en $data
        $this->set('supervisor', $this->Supervisor->read()); //lee la ref con id hacia $data
        $this->set('id', $id);
    }

    function agregar() {//copiado del manual
        if (!empty($this->data)) {//si existen dato
            if ($this->Supervisor->save($this->data)) {//si al op es true
                $this->Session->setFlash('Supervisor agregado exitosamente.'); //msg
                $this->redirect(array('action' => 'index')); //ir a lista
            } else {
                $this->Session->setFlash('Error al agregar supervisor');
                $this->redirect(array('action' => 'index'));
            }
        }
    }

    function borrar($id) {
        if ($this->Supervisor->delete($id)) {
            $this->Session->setFlash('Supervisor eliminado exitosamente.');
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash('Error al borrar supervisor');
            $this->redirect(array('action' => 'index'));
        }
    }

    function editar($id) {
        $this->Supervisor->id = $id; //ref id hacia $data
        if (empty($this->data)) {//si la data esta vacia
            $this->data = $this->Supervisor->read(); //leer del id (llena datos)
            $this->set('id', $id);
        } else {
            if ($this->Supervisor->save($this->data)) {//save data
                $this->Session->setFlash('Supervisor editado exitosamente.');
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash('Error al editar supervisor');
                $this->redirect(array('action' => 'index'));
            }
        }
    }

}

?>
